<?php
namespace app\index\controller;
use app\common\controller\Frontend;
class Ajax extends Frontend{

    public function upload(){

        $file = $this->request->file('file');
        
        $info = $file->move(ROOT_PATH . 'public' . DS . 'storage');
        if($info){
            $fileInfo = $file->getInfo();
            $fileData['storage'] = DS.'public' . DS . 'storage';
            $fileData['source_name'] = $fileInfo['name'];
            $fileData['mini_type'] = $fileInfo['type'];
            $fileData['file_size'] = $fileInfo['size'];
            $fileData['file_extension'] = $info->getExtension();
            $fileData['file_name'] = $info->getFilename();
            $fileData['url'] = DS . 'storage'. DS.$info->getSaveName();
            model('FileAttachments')->save($fileData);
            $this->result($fileData['url'],1);
        }else{
            $this->error($file->getError());
        }
    }
    
}